package com.yjy.controller;

import com.yjy.entity.OrderInfo;
import com.yjy.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class OrderInfoController {

    @Autowired
    private OrderInfoService orderInfoService;

    /**
     * 保存订单信息
     *
     * @return 保存结果
     */
    @RequestMapping(value = "/save")
    public String saveOrderInfo() {
        for (int i = 0; i < 1000; i++) {
            orderInfoService.save();
        }
        return "保存成功";
    }


    @GetMapping(value = "/list")
    public List<OrderInfo> list() {
        return orderInfoService.getAll();
    }

    @GetMapping("/page/{page}")
    public Page<OrderInfo> page(@PathVariable("page") int page) {
        Pageable request = PageRequest.of(page, 10);
        return orderInfoService.page(request);
    }
}
